<template>
  <div class="viewcontainer" v-if="dataset">
    <el-row class="view-header">
      <el-col :span="22">
        <hi-lquery
          :columnsTotal="3"
          v-bind="queryPanel"
          :target="dataset"
        ></hi-lquery>
      </el-col>
    </el-row>
    <el-row class="view-main">
      <el-table
        ref="dataTable"
        :data="dataset.data"
        height="100%"
        style="width: 100%"
        v-loading="dataset.loading"
      >
        <el-table-column type="index" width="50" />
        <el-table-column prop="doctor_name" label="医生姓名" width="140" />
        <el-table-column prop="patient_name" label="患者姓名" width="140" />
        <el-table-column prop="take_drug" label="是否取药" width="180">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.take_drug">{{
              takeDrug(scope.row.take_drug)
            }}</el-tag>
            <el-tag type="danger" v-else>{{
              takeDrug(scope.row.take_drug)
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="payment_or_not" label="是否付款" width="180">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.payment_or_not">{{
              payment(scope.row.payment_or_not)
            }}</el-tag>
            <el-tag type="danger" v-else>{{
              payment(scope.row.payment_or_not)
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="create_date" label="创建时间" />
        <el-table-column fixed="right" label="操作" width="80">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="showDetail(scope.row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row class="view-footer pagebar">
      <hi-pagination
        background
        :total="dataset.total"
        :target="dataset"
      ></hi-pagination>
    </el-row>
  </div>
</template>
<script>
import { HiPagination, HiLquery } from "hi-ui";
import viewBase from "../../base";
import prescriptionListCfg from "./dataset/prescriptionList";
export default {
  name: "prescriptionList",
  extends: viewBase,
  components: { HiPagination, HiLquery },
  data() {
    let datasetCfg = Object.assign({}, prescriptionListCfg, {
      action: "autoAction",
    });
    return {
      //数据桥梁
      dataBridge: new Map(),
      dataset: null,
      //数据集配置
      datasetCfg: datasetCfg,

      total: 100,
      //查询面板配置
      queryPanel: {
        fields: [
          {
            element: "el-input",
            label: "医生姓名",
            name: "doctor_name",
          },
          {
            element: "el-input",
            label: "患者姓名",
            name: "patient_name",
          },
        ],
      },
    };
  },

  computed: {},
  watch: {},
  methods: {
    //是否取药
    takeDrug(val) {
      if (val) return "已取药";
      else return "未取药";
    },
    //是否付款
    payment(val) {
      if (val) return "已付款";
      else return "未付款";
    },
    //详情
    showDetail(data) {
      this.openByPath(
        "/sales/prescription/detail/",
        { id: data.record_id },
        { title: "处方详情", target: "_blank" }
      );
    },
  },
  mounted() {
    //创建数据集
    this.dataset = this.createDataSet(this.datasetCfg);
    this.dataBridge.set(this.dataset, ["dataTable"]);
  },
};
</script>
<style rel="stylesheet/scss" lang="scss" scope>
</style>